package org.news.dao;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.news.beans.Users;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath*:applicationContext.xml"})
public class UsersDao {

    @Autowired
    SqlSessionFactory sessionFactory;
    @Test
    public void tsetfindAllObject() {
        SqlSession s = sessionFactory.openSession();
        List<Users> usersList = s.selectList("org.news.beans.selectAll");
        for ( Users u : usersList ) {
            System.out.println(u + "OOOOOOOOOOOOOOOOOO");
        }
    }
    @Test
    public void findOneObject() {
        Users users = new Users();
        users.setUsername("admin123");
        users.setUserpwd("admin123");
        System.out.print(users);
        SqlSession s = sessionFactory.openSession();
        users = s.selectOne("org.news.beans.selectUsers",users);
        System.out.println(users+"PPPPPPPPPPPPPPPP");
        s.close();
    }
    @Test
    public void save() {
        Users users = new Users();
        users.setUsername("kk");
        users.setUserpwd("yy");
        SqlSession s = sessionFactory.openSession();
        Integer key = s.insert("org.news.beans.insertUsers",users);
        s.close();
    }
}

